<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_dynamicPlot"></title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%;
            position: absolute;
            top: 0;
        }

        #map {
            position: absolute;
            left: 250px;
            right: 0px;
            height: 100%;
            border: 1px solid #3473b7;
        }

        #plottingMenu {
            position: absolute;
            top: 20%;
            z-index: 888;
            border-radius: 4px;
            padding-top: 2px;
            left: 265px;
            color: #000000;
            background-color: #fff;
        }

        #plottingPanel {
            float: left;
            background: #ffffff;
            width: 250px;
            height: 100%;
            border: 1px solid #3473b7;
        }
    </style>
</head>
<body>
<div id="map"></div>
<div id="plottingPanel">
    <div class="easyui-panel" style="position:absolute;top:0px;bottom:0px;left:0px;right:0px;padding:5px; width: 100%;">
        <div class="easyui-tabs" style="width: 100%;height: 100%">
            <div id="plotPanel" data-i18n="[title]resources.text_drawPanel" style="overflow: hidden"></div>
            <div id="stylePanel" data-i18n="[title]resources.text_attributePanel"></div>
        </div>
    </div>
</div>
<div id="plottingMenu" class="sticklr">
    <li>
        <a class="glyphicon plotting-glyphicon-draw-deactivate notArrow"
           data-i18n="[title]resources.text_cancelDraw"
           onclick="cancelDraw()"></a>
    </li>
    <li>
        <a class="glyphicon plotting-glyphicon-draw-removeAll notArrow"
           data-i18n="[title]resources.text_input_value_clear"></a>
        <ul>
            <li><input type="button" data-i18n="[value]resources.btn_deleteMarker" onclick="deleteSymbol()"
                       style="width:70px;height: 25px ;margin:0 auto;"/> </li>
            <li><input type="button" data-i18n="[value]resources.btn_clearLayers" onclick="clearLayer()"
                       style="width: 70px;height: 25px ;margin:0 auto;"/></li>
        </ul>
    </li>
    <li>
        <a class="glyphicon glyphicon-pencil notArrow" data-i18n="[title]resources.text_editor"></a>
        <ul>
            <li><input type="button" data-i18n="[value]resources.btn_copy" onclick="copySymbol()"
                       style="width:70px;height: 25px ;margin:0 auto;"/> </li>
            <li><input type="button" data-i18n="[value]resources.btn_cut" onclick="cutSymbol()"
                       style="width: 70px;height: 25px ;margin:0 auto;"/></li>
            <li><input type="button" data-i18n="[value]resources.btn_paste" onclick="pasteSymbol()"
                       style="width: 70px;height: 25px ;margin:0 auto;"/></li>
        </ul>
    </li>
    <li>
        <a class="glyphicon glyphicon-plus notArrow" data-i18n="[title]resources.text_addLayer" onclick="addPlottingLayer()"></a>
    </li>
    <li>
        <a class="glyphicon plotting-lyphicon-save-simulationMap" data-i18n="[title]resources.text_situationMapOperation"></a>
        <ul>
            <li><input type="button" data-i18n="[value]resources.btn_saveSimulationMap" onclick="saveSimulationMap()"
                       style="width:70px;height: 25px ;margin:0 auto;"/> </li>
            <li><input type="button" data-i18n="[value]resources.btn_loadSimulationMap" onclick="loadSimulationMap()"
                       style="width: 70px;height: 25px ;margin:0 auto;"/></li>
        </ul>
    </li>
    <li>
        <a class="glyphicon glyphicon-edit notArrow" data-i18n="[title]resources.text_editMarker"></a>
        <ul>
            <li><input type="button" data-i18n="[value]resources.btn_editRectangle" onclick="editCircusRetangle()"
                       style="width:85px;height: 25px ;margin:0 auto;"/> </li>
            <li><input type="button" data-i18n="[value]resources.btn_editNode" onclick="editContorPoints()"
                       style="width:70px;height: 25px ;margin:0 auto;"/> </li>
            <li><input type="button" data-i18n="[value]resources.btn_addNode" onclick="addControlPoints()"
                       style="width: 70px;height: 25px ;margin:0 auto;"/></li>
            <li><input type="button" data-i18n="[value]resources.btn_deleteNode" onclick="removeControlPoints()"
                       style="width: 70px;height: 25px ;margin:0 auto;"> </input></li>
        </ul>
    </li>
    <li>
        <a class="glyphicon glyphicon-lock notArrow" data-i18n="[title]resources.text_aboutMode"></a>
        <ul>
            <li><input type="button" data-i18n="[value]resources.btn_lockSwitch" onclick="setPlottingLayerIsLocked()"
                       style="width:85px;height: 25px ;margin:0 auto;"/> </li>
            <li><input type="button" data-i18n="[value]resources.btn_editSwitch" onclick="setPlottingLayerIsEdit()"
                       style="width:85px;height: 25px ;margin:0 auto;"/> </li>
            <li><input type="button" data-i18n="[value]resources.btn_selectSwitch" onclick="setPlottingLayerIsSelected()"
                       style="width:85px;height: 25px ;margin:0 auto;"/> </li>
        </ul>
    </li>
    <li>
        <a class="glyphicon glyphicon-check notArrow"   data-i18n="[title]resources.text_multiselect" onclick="multiSelectModel()"></a>

    </li>
    <li>
        <a class="glyphicon glyphicon-align-justify notArrow" data-i18n="[title]resources.text_multiselectAlign"></a>
        <ul>
            <li><input type="button" data-i18n="[value]resources.btn_leftAlignment" onclick="setSymbolAlighLeft()"
                       style="width:70px;height: 25px ;margin:0 auto;"/> </li>
            <li><input type="button" data-i18n="[value]resources.btn_rightAlignment" onclick="setSymbolAlighRight()"
                       style="width: 70px;height: 25px ;margin:0 auto;"/></li>

            <li><input type="button" data-i18n="[value]resources.btn_topAlignment" onclick="setSymbolAlighUp()"
                       style="width:70px;height: 25px ;margin:0 auto;"/> </li>

            <li><input type="button" data-i18n="[value]resources.btn_bottomAlignment" onclick="setSymbolAlighDown()"
                       style="width:70px;height: 25px ;margin:0 auto;"/> </li>
            <li><input type="button" data-i18n="[value]resources.btn_verticalCenter" onclick="setSymbolAlighVerticalcenter()"
                       style="width:70px;height: 25px ;margin:0 auto;"/> </li>
            <li><input type="button" data-i18n="[value]resources.btn_horizontalCenter" onclick="setSymbolAlighHorizontalcenter()"
                       style="width:70px;height: 25px ;margin:0 auto;"/> </li>
        </ul>
    </li>

    <li>
        <a class="glyphicon glyphicon-adjust notArrow" data-i18n="[title]resources.text_avoid"></a>
        <ul>
            <li><input type="button" data-i18n="[value]resources.btn_avoidEdit" onclick="drawAvoidRegion()"
                       style="width:80px;height: 25px ;margin:0 auto;"/> </li>
            <li><input type="button" data-i18n="[value]resources.btn_cancelAvoidEdit" onclick="doneAvoidEdit()"
                       style="width:80px;height: 25px ;margin:0 auto;"/> </li>
            <li><input type="button" data-i18n="[value]resources.btn_deleteAvoid" onclick="deleteAvoidEdit()"
                       style="width:80px;height: 25px ;margin:0 auto;"/> </li>
        </ul>
    </li>
    <li>
        <a class="glyphicon glyphicon-gift notArrow" data-i18n="[title]resources.text_createGroup"></a>
        <ul>
            <li><input type="button" data-i18n="[value]resources.btn_group" onclick="createGroupObjects()"
                       style="width:70px;height: 25px ;margin:0 auto;"/> </li>
            <li><input type="button" data-i18n="[value]resources.btn_flags" onclick="createDrawFlags()"
                       style="width:70px;height: 25px ;margin:0 auto;"/> </li>
            <li><input type="button" data-i18n="[value]resources.btn_unbundling" onclick="unGroupObject()"
                       style="width:70px;height: 25px ;margin:0 auto;"/> </li>
        </ul>
    </li>
    <li>
        <a class="glyphicon glyphicon-arrow-left notArrow" data-i18n="[title]resources.btn_undo" onclick="undo()"></a>
    </li>
    <li>
        <a class="glyphicon glyphicon-arrow-right notArrow" data-i18n="[title]resources.btn_redo" onclick="redo()"></a>
    </li>
    <li>
        <a  class="glyphicon glyphicon-th-large notArrow" data-i18n="[title]resources.text_symbolEqualSize" ></a>
        <ul>
            <li><input type="button" data-i18n="[value]resources.btn_symbolEqualWidth" onclick="setSymbolEqualWidth()"
                       style="width:70px;height: 25px ;margin:0 auto;"> </input> </li>
            <li><input type="button" data-i18n="[value]resources.btn_symbolEqualHeight" onclick="setSymbolEqualHeight()"
                       style="width: 70px;height: 25px ;margin:0 auto;"> </input></li>
            <li><input type="button" data-i18n="[value]resources.btn_symbolEqualWidthHeight" onclick="setSymbolEqualWidthHeight()"
                       style="width:70px;height: 25px ;margin:0 auto;"> </input> </li>
        </ul>
    </li>
    <li>
        <a  class="glyphicon glyphicon-th" data-i18n="[title]resources.text_symbolDistribution" ></a>
        <ul>
            <li><input type="button"  data-i18n="[value]resources.btn_symbolLevelDistribution" onclick="setSymbolLevelDistribution()"
                       style="width:70px;height: 25px ;margin:0 auto;"> </input> </li>
            <li><input type="button" data-i18n="[value]resources.btn_symbolVerticalDistribution" onclick="setSymbolVerticalDistribution()"
                       style="width: 70px;height: 25px ;margin:0 auto;"> </input></li>
        </ul>
    </li>
</div>
<div id="contentMe" style="width:100px;background-color:#f4f4f4;box-shadow:3px 3px 3px rgba(0,0,0,0.5);position:absolute;z-index:1000; top:20px;left:100px;display:none;text-align:center;">
    <a href="javascript:void(0)" id="paste" style="border-bottom:1px solid #ccc;display:block;line-height:20px;color:#000; font-size:16px;">粘贴此处</a>
</div>
<script type="text/javascript" include="bootstrap,responsive,sticklr,plottingPanel" src="../js/include-web.js"></script>
<script type="text/javascript"  include="iclient9-plot-leaflet" src="../../dist/leaflet/include-leaflet.js"></script>
<script type="text/javascript" include="PlotPanel,StylePanel" src="../js/plottingPanel/PlottingPanel.Include.js"></script>

<script type="text/javascript">
    var host = window.isLocal ? window.server : "http://iclsvr.supermap.io";
    var url = host + "/iserver/services/map-china400/rest/maps/China_4326";
    var serverUrl = host + "/iserver/services/plot-jingyong/rest/plot/";


    var map;
    map = L.map('map', {
        preferCanvas: true,
        crs: L.CRS.EPSG4326,
        center: [35, 104],
        maxZoom: 18,
        zoom: 3
    });
    L.supermap.tiledMapLayer(url).addTo(map);
    var plottingLayer = L.supermap.plotting.plottingLayer("plot", serverUrl);
    plottingLayer.spatialAnalystUrl=host+"/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst";
    plottingLayer.addTo(map);
    var drawControl = L.supermap.plotting.drawControl(plottingLayer);
    drawControl.addTo(map);
    var editControl = L.supermap.plotting.editControl();
    editControl.addTo(map);
    L.supermap.plotting.initPlotPanel("plotPanel", serverUrl, drawControl);
    L.supermap.plotting.initStylePanel("stylePanel", serverUrl, editControl);

    var plotting = L.supermap.plotting.getControl(map, serverUrl);

    map.on('contextmenu', function (event) {
        if(editControl.getSelectedFeatures().length == 0){
            return;
        }
        var contentMe = document.getElementById("contentMe");
        contentMe.style.top = event.originalEvent.clientY + "px";
        contentMe.style.left = event.originalEvent.clientX + "px";
        contentMe.style.display = "block";
        document.getElementById("paste").onclick = function(){
            editControl.paste(event.latlng);
        };
    }).on('mousemove', function (event) {
        contentMe.style.display = "none";
    });

    //取消标绘
    function cancelDraw() {
        drawControl.handler.disable();
    }

    //清空绘制
    function clearLayer() {
        cancelDraw();

        for(var i = 0; i < map.getPlottingLayers().length; i++){
            map.getPlottingLayers()[i].removeAllFeatures();
        }
    }

    //删除选中标号
    function deleteSymbol() {
        editControl.deleteSelectedFeatures();
    }

    //复制
    function copySymbol() {
        editControl.copy();
    }

    //剪切
    function cutSymbol() {
        editControl.cut();
    }

    //粘贴
    function pasteSymbol() {
        editControl.paste();
    }

    //添加图层
    function addPlottingLayer() {
        cancelDraw();

        var plottingLayerName = "plottingLayer_" + Math.ceil(Math.random() * 1000);
        var plottingLayerNew = L.supermap.plotting.plottingLayer(plottingLayerName, serverUrl);
        drawControl.setDrawingLayer(plottingLayerNew);
        plottingLayerNew.addTo(map);

        alert("标绘图层"+plottingLayerNew.name+"增加成功!");
    }

    //保存态势图
    function saveSimulationMap() {
        cancelDraw();
        plotting.getSitDataManager().saveAsSmlFile("situationMap");
    }

    function loadSimulationMap() {
        plotting.getSitDataManager().openSmlFileOnServer("situationMap", function(evt){
            drawControl.setDrawingLayer(evt.sitDataLayers[0]);
        });
    }

    function editCircusRetangle() {
        editControl.setEditMode(SuperMap.Plot.EditMode.EDITCIRCUMRECTANGLE);
    }

    function editContorPoints() {
        editControl.setEditMode(SuperMap.Plot.EditMode.EDITCONTROLPOINT);
    }

    function addControlPoints() {
        editControl.setEditMode(SuperMap.Plot.EditMode.ADDCONTROLPOINT);
    }
    function removeControlPoints(){
        editControl.setEditMode(SuperMap.Plot.EditMode.REMOVECONTROLPOINT);
    }
    //切换多选模式
    function multiSelectModel() {
        editControl.multiSelect();
    }

    //多选对齐--左对齐
    function setSymbolAlighLeft() {
        editControl.align(SuperMap.Plot.AlignType.LEFT);
    }

    //多选对齐--右对齐
    function setSymbolAlighRight() {
        editControl.align(SuperMap.Plot.AlignType.RIGHT);
    }

    //多选对齐--上对齐
    function setSymbolAlighUp() {
        editControl.align(SuperMap.Plot.AlignType.UP);
    }

    //多选对齐--下对齐
    function setSymbolAlighDown() {
        editControl.align(SuperMap.Plot.AlignType.DOWN);
    }

    //多选对齐--竖直居中对齐
    function setSymbolAlighVerticalcenter() {
        editControl.align(SuperMap.Plot.AlignType.VERTICALCENTER);
    }

    //多选对齐--水平居中对齐
    function setSymbolAlighHorizontalcenter() {
        editControl.align(SuperMap.Plot.AlignType.HORIZONTALCENTER);
    }

    //切换图层是否锁定
    function setPlottingLayerIsLocked() {
        if (plottingLayer.getLocked() === true) {
            plottingLayer.setLocked(false);
        } else {
            plottingLayer.setLocked(true);
        }
    }

    //切换图层是否可编辑模式
    function setPlottingLayerIsEdit() {
        if (plottingLayer.getEditable() === true) {
            plottingLayer.setEditable(false);
        } else {
            plottingLayer.setEditable(true);
        }
    }

    //切换图层是否可选择模式
    function setPlottingLayerIsSelected() {
        if (plottingLayer.getSelected() === true) {
            plottingLayer.setSelected(false);
        } else {
            plottingLayer.setSelected(true);
        }
    }

    function drawAvoidRegion(){
        if (editControl._avoidEditing === false && editControl.getSelectedFeatures().length === 0) {
            return;
        }else{
            editControl.avoidEdit(true);
        }
    }
    function doneAvoidEdit(){
        editControl.avoidEdit(false);
    }
    function deleteAvoidEdit(){
        if (editControl._avoidEditing === false && editControl.getSelectedFeatures().length === 0) {
            return ;
        }else if(editControl._avoidEditing === true){
            editControl.avoidEdit(false);
            editControl.getSelectedFeatures()[0].removeAvoidRegions();
        }
    }

    //创建组合对象
    function createGroupObjects() {
        var features = editControl.getSelectedFeatures();
        if (features.length >= 2) {
            var groupObject = plottingLayer.createGroupObject(features);
            if(!!groupObject){
                editControl.selectFeatures(groupObject);
            }
            var feature = plottingLayer.features[plottingLayer.features.length-1];
            var transaction = new SuperMap.Plot.Transaction();
            transaction.transType = SuperMap.Plot.TransactionType.EDIT;
            var transInfo = new SuperMap.Plot.TransactionInfo();
            transInfo.layerId = plottingLayer._leaflet_id;
            transInfo.uuid = feature.uuid;
            transInfo.functionName = "createGroupObject";
            transInfo.undoParams = [feature];
            transInfo.redoParams = [features];
            transaction.transInfos.push(transInfo);
            L.supermap.plotting.getControl().getTransManager().add(transaction);
        }

    }

    //创建多旗
    function createDrawFlags() {
        var features = editControl.getSelectedFeatures();
        if (features.length >= 2) {
            var flagObject = plottingLayer.createFlags(features);
            if(!!flagObject){
                editControl.selectFeatures(flagObject);
            }
            var transaction = new SuperMap.Plot.Transaction();
            transaction.transType = SuperMap.Plot.TransactionType.EDIT;
            var transInfo = new SuperMap.Plot.TransactionInfo();
            transInfo.layerId = flagObject.layer._leaflet_id;
            transInfo.uuid = flagObject.uuid;
            transInfo.functionName = "createFlags";
            transInfo.undoParams = [flagObject];
            transInfo.redoParams = [features];
            transaction.transInfos.push(transInfo);
            L.supermap.plotting.getControl().getTransManager().add(transaction);
        }
    }

    //解绑组合对象
    function unGroupObject() {
        var features = editControl.getSelectedFeatures();
        for (var i = features.length - 1; i >= 0; i--) {
            if (features[i] instanceof L.supermap.plotting.GroupObject) {
                var subLayers = plottingLayer.unGroupObject(features[i]);
                editControl.selectFeatures(subLayers);
            }

        }
    }

    function undo(){
        editControl.avoidEdit(false);
        plotting.getTransManager().undo();
        editControl.fire(SuperMap.Plot.Event.featuresmodified);//刷新属性面板
    }

    function redo(){
        editControl.avoidEdit(false);
        plotting.getTransManager().redo();
        editControl.fire(SuperMap.Plot.Event.featuresmodified);//刷新属性面板
    }

    //等大
    //等宽
    function setSymbolEqualWidth(){
        editControl.equalLarge(SuperMap.Plot.EqualLargeType.WIDTH);
    }
    //等高
    function setSymbolEqualHeight(){
        editControl.equalLarge(SuperMap.Plot.EqualLargeType.HEIGHT);
    }
    //等宽高
    function setSymbolEqualWidthHeight(){
        editControl.equalLarge(SuperMap.Plot.EqualLargeType.SAME);
    }

    //均匀分布
    //横向均匀分布
    function setSymbolLevelDistribution(){
        editControl.uniformDistribution(SuperMap.Plot.UniformDistributionType.LEVEL);
    }

    //纵向均匀分布
    function setSymbolVerticalDistribution(){
        editControl.uniformDistribution(SuperMap.Plot.UniformDistributionType.VERTICAL);
    }

    document.onkeydown = function (event) {
        var event = event || window.event;
        if(event && event.keyCode === 46){//Delete键
            editControl.deleteSelectedFeatures();
        }
    }

</script>
</body>
</html>



